<?php
class PositionsController extends AppController {
	var $name = 'Positions';
	var $uses = array('Position', 'Department');

	function index() {
		$this->set('positions', $this->Position->find('all'));
	}
	
	function view($id = null) {
		$this->Position->id = $id;
		$this->set('position', $this->Position->read());
	}
	
	function add() {
		$this->set('departments', $this->Department->find('list'));
		
		if (!empty($this->data)) {
			if ($this->Position->save($this->data)) {
				$this->flash('You have successfully added a Position.', '/positions');
			}
		}
	}
	
	function delete($id) {
		$this->Position->del($id);
		$this->flash('You have successfully removed Position ' . $id . '.', '/positions');
	}
	
	function edit($id) {
		$this->Position->id = $id;
		if (empty($this->data)) {
			$this->data = $this->Position->read();
			$this->set('departments', $this->Department->find('list'));
		}
		else {
			if ($this->Position->save($this->data)) {
				$this->flash('The Position has been updated.', '/positions');
			}
		}
	}
}
?>